package com.course.entity;

public class Student extends Person {
    private Course selectedCourse;  // 特有属性：已选课程

    // 子类构造方法：通过super()调用父类构造
    public Student(String studentId, String name, String gender) {
        super(studentId, name, gender);  // 初始化id、name、gender
    }

    // 选课方法
    public void selectCourse(Course course) {
        this.selectedCourse = course;
        System.out.println(name + " 已选课程：" + course.getCourseName());
    }

    // 退课方法
    public void dropCourse() {
        if (selectedCourse != null) {
            System.out.println(name + " 已退课：" + selectedCourse.getCourseName());
            this.selectedCourse = null;
        } else {
            System.out.println(name + " 暂无选课记录，无法退课");
        }
    }

    // 重写父类抽象方法：打印学生课表
    @Override
    public void printWorksheet() {
        if (selectedCourse != null) {
            System.out.println("学生课表---");
            System.out.println("学生编号：" + id);  // 访问父类protected属性id
            System.out.println("课程名称：" + selectedCourse.getCourseName());
            System.out.println("上课地点：" + selectedCourse.getLocation());
            System.out.println("上课时间：" + selectedCourse.getTime());
        } else {
            System.out.println(id + " 暂无选课记录，课表为空");
        }
    }

    public Course getSelectedCourse() {
        return selectedCourse;
    }
}